package com.idealighter.game.games.happyfive.struct;

import com.google.common.collect.Lists;

import com.idealighter.game.games.happyfive.struct.cards.Card;
import com.idealighter.game.games.happyfive.struct.cards.CardNumber;
import com.idealighter.game.games.happyfive.struct.cards.CardSuit;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * .. 欢乐五张.
 * 
 * @date 2016年1月16日 下午8:23:41
 */

public class HappyFiveCards {
  private final List<Card> cards = Lists.newArrayList();

  /**
   * 欢乐五张.
   */
  public HappyFiveCards() {
    for (CardSuit suit : CardSuit.values()) {
      for (CardNumber number : CardNumber.values()) {
        Card card = new Card(suit, number);
        cards.add(card);
      }
    }

    Collections.shuffle(cards);
  }

  public List<Card> getCards() {
    return cards;
  }

  public Card removeTopCard() {
    return cards.remove(0);
  }

  public boolean removeCard(Card card) {
    return cards.remove(card);
  }

  /**
   * .
   * 
   * @return
   */
  public List<List<Card>> fromDeckToCouplesOfCard() {
    List<List<Card>> couplesOfCard = new ArrayList<List<Card>>();
    for (int i = 0; i < this.cards.size(); i++) {
      for (int j = i + 1; j < this.cards.size(); j++) {
        List<Card> tmpCards = new ArrayList<Card>();
        tmpCards.add(this.cards.get(i));
        tmpCards.add(this.cards.get(j));
        couplesOfCard.add(tmpCards);
      }
    }
    return couplesOfCard;
  }
}
